package edu.cuit.zhuyimeng.aircraft.controller;

import edu.cuit.zhuyimeng.aircraft.controller.vo.AircraftInfoVO;
import edu.cuit.zhuyimeng.aircraft.controller.vo.FormatAircraftInfoVO;
import edu.cuit.zhuyimeng.aircraft.convert.AircraftConverter;
import edu.cuit.zhuyimeng.aircraft.dal.po.AirlinePO;
import edu.cuit.zhuyimeng.aircraft.service.IAircraftService;
import edu.cuit.zhuyimeng.framework.common.result.CommonResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 飞机查询控制器
 */
@RestController
@Tag(name = "飞机查询控制器", description = "飞机查询控制器")
@RequestMapping("/aircraft")
@Validated
@RequiredArgsConstructor
public class GenericController {

    private final IAircraftService aircraftService;

    /**
     *  查询飞机信息
     * @param id 飞机ID
     */
    @Operation(summary = "查询飞机信息",security = @SecurityRequirement(name = "Authorization"))
    @GetMapping("/")
    public CommonResult<AircraftInfoVO> getAircraftInfo(@RequestParam("id") @NotNull Long id) {
        return CommonResult.success(aircraftService.getAircraftInfo(id));
    }

    /**
     * 查询飞机列表
     */
    @Operation(summary = "查询飞机列表",security = @SecurityRequirement(name = "Authorization"))
    @GetMapping("/list")
    public CommonResult<List<AircraftInfoVO>> getAircraftList(@RequestParam("page") @NotNull Integer page) {
        return CommonResult.success(aircraftService.getAircraftList(page));
    }

    /**
     * 查询格式化的飞机列表
     */
    @Operation(summary = "查询格式化的飞机列表（Ant Design 级联）",security = @SecurityRequirement(name = "Authorization"))
    @GetMapping("/format/list")
    public CommonResult<List<FormatAircraftInfoVO>> getFormatAircraftList() {
        return CommonResult.success(AircraftConverter.formatToFormatAircraftInfoVO(aircraftService.getAircraftList()));
    }

    /**
     * 查询所有航空公司
     */
    @Operation(summary = "查询所有航空公司",security = @SecurityRequirement(name = "Authorization"))
    @GetMapping("/airline")
    public CommonResult<List<AirlinePO>> getCompanyList() {
        return CommonResult.success(aircraftService.getAirlineList());
    }

}
